//
//  UIUtils.m
//  GcwSDKDemo
//
//  Created by 陈超 on 2017/7/25.
//  Copyright © 2017年 陈超. All rights reserved.
//

#import "UIUtils.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import <AVFoundation/AVFoundation.h>
@implementation UIUtils
//将View 及其子显示对象转换为UIImage
+ (UIImage *)viewShot:(UIView*)view
{
    // 将要被截图的view,窗口的根控制器的view(iOS6,默认控制器不含状态栏)
    // 开启上下文,使用参数之后,截出来的是原图（YES  0.0 质量高）
    UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, 0.0);
    // 将cutView的图层渲染到上下文中
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    // 取出UIImage
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    // 添加截取好的图片到图片数组
    
    // 千万记得,结束上下文
    UIGraphicsEndImageContext();
    return image;
}
+(CGSize)getVideoSize:(NSURL *)videoUrl{
    AVURLAsset *videoAsset=[AVURLAsset assetWithURL:videoUrl];
    AVAssetTrack *videoAssetTrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
    
    return videoAssetTrack.naturalSize;
}
+(Float64)getVideoDuration:(NSURL *)videoUrl{
    AVURLAsset *videoAsset=[AVURLAsset assetWithURL:videoUrl];
    return CMTimeGetSeconds(videoAsset.duration);
}
@end
